package com.chen.Dome2API;

public class APIDome3 {
    public static void main(String[] args) {
        //目标：搞清楚join()方法的作用
        Thread mt = new MyThread2("1号");
        mt.start();
        for(int i = 0; i < 5; i++){
            System.out.println("主线程在跑" + i);
            if(i == 1) {
                try {
                    mt.join();//让主线程等待mt线程执行完毕
                    //线程阻塞，等待mt线程执行完毕
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
class MyThread2 extends Thread {
    //使用有参构造器设置线程名称
    public MyThread2(String name) {
        super(name);
    }

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {

            System.out.println("子线程" + Thread.currentThread().getName() + "在跑" + i);

        }
    }
}
